package com.applancer.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.applancer.model.FeedModel;
import com.applancer.model.GeneralModel;
import com.applancer.nativecmsflip.R;
import com.squareup.picasso.Picasso;

public class BookmarksAdapter extends ArrayAdapter<GeneralModel> {

	protected List<GeneralModel> ldata;

	public BookmarksAdapter(Context context, List<GeneralModel> objects) {
		super(context, R.layout.adapter_feed, objects);

		ldata = objects;
	}

	@Override
	public int getCount() {
		return ldata.size();
	}

	@Override
	public GeneralModel getItem(int position) {
		return ldata.get(position);
	}

	@Override
	public long getItemId(int position) {
		return Integer.parseInt(((FeedModel) getItem(position)).getId());
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		FeedModel model = (FeedModel) getItem(position);

		ViewHolder holder;

		if (convertView == null) {

			LayoutInflater inflater = LayoutInflater.from(parent.getContext());
			convertView = inflater.inflate(R.layout.adapter_feed, null);

			holder = new ViewHolder();
			holder.thumb = (ImageView) convertView.findViewById(R.id.thumb_id);
			holder.textview_title = (TextView) convertView
					.findViewById(R.id.title_id);
			holder.textview_author = (TextView) convertView
					.findViewById(R.id.author_id);
			// holder.textComment = (TextView) convertView
			// .findViewById(R.id.feed_comment_id);
			// holder.textLike = (TextView) convertView
			// .findViewById(R.id.feed_like_id);
			// holder.textShare = (TextView) convertView
			// .findViewById(R.id.feed_share_id);

			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		try {
			holder.textview_title.setText(model.getTitle());
		} catch (Exception e) {

		}

		holder.textview_author.setText(model.getDate() == null ? "" : model
				.getDate());
//		holder.textComment
//				.setText(((model.getCountCommentFB().equals("")) ? "0" : model
//						.getCountCommentFB()) + " comment");
//		holder.textLike.setText(((model.getCountLikeFB().equals("")) ? "0"
//				: model.getCountLikeFB()) + " like");
//		holder.textShare.setText(((model.getCountShareFB().equals("")) ? "0"
//				: model.getCountShareFB()) + " share");

		Picasso.with(parent.getContext()).load(model.getUrlImageThumb())
				.placeholder(R.drawable.ic_launcher)
				.error(R.drawable.ic_launcher).fit().centerCrop()
				.into(holder.thumb);

		return convertView;
	}

	static class ViewHolder {
		ImageView thumb;
		TextView textview_title;
		TextView textview_author;
//		TextView textComment;
//		TextView textLike;
//		TextView textShare;
	}

}
